package com.harmontronics.hanma.paas.paas.domain.iam.repository.persistence;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.harmontronics.hanma.paas.paas.domain.iam.entity.valueobject.Fields;
import com.harmontronics.hanma.paas.paas.domain.iam.repository.mapper.HmMenuMapper;
import com.harmontronics.hanma.paas.paas.domain.iam.repository.po.HmMenuPO;
import org.springframework.stereotype.Repository;


/**
 * @author 吕大兵
 */
@Repository("hmMenuRepository")
public class HmMenuRepository extends ServiceImpl<HmMenuMapper, HmMenuPO> {

    public IPage<HmMenuPO> selectPage(QueryWrapper<HmMenuPO> queryWrapper, Page<HmMenuPO> page) {
        return baseMapper.selectPage(page, queryWrapper);
    }

    /**
     * 页面是否被菜单引用
     * @param pageId
     * @return
     */
    public boolean existsByPage(Long pageId) {
        QueryWrapper<HmMenuPO> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq(Fields.PAGE_ID,pageId);
        queryWrapper.last("limit 1");
        return baseMapper.selectCount(queryWrapper) == 1;
    }
}